<template>
  <div class="app-container">
    <div v-show="!modifyInfo.visible && !detailInfo.visible">
      <!-- 条件栏 -->
      <div class="filter-wrapper">
        <NewPageFilter
          v-model:query="filterInfo.query"
          :query-more-json="false"
          :filter-list="filterInfo.searchList"
          :filter-btn="filterInfo.searchBtn"
          :clear-type="clearType"
        >
        </NewPageFilter>
      </div>
      <div class="filter-wrapper">
        <NewPageFilter :filter-btn="filterInfo.btnList"> </NewPageFilter>
      </div>
      <!-- 表格 -->
      <TableContainer
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        v-model:query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        :handle="tableInfo.handle"
        :row-class-name="tableRowClassName"
      >
        <template v-slot:col-name="scope">
          <span class="slip-edit" @click="showDetail(scope.row)">{{
            scope.row.name
          }}</span>
        </template>
      </TableContainer>
    </div>

    <Modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      :orderId="modifyInfo.orderId"
      @returnModify="returnModify"
    />

    <Detail
      v-if="detailInfo.visible"
      v-model:visible="detailInfo.visible"
      :orderId="detailInfo.orderId"
      @returnBack="getList"
    />
  </div>
</template>

<script setup name="biddingParameter">
import { getParameterPage, delParameter } from '@/api/bidding'
import Modify from './modify'
import Detail from './detail'
import { onMounted } from 'vue'
const { proxy } = getCurrentInstance()
// 过滤相关配置
const filterInfo = ref({
  query: {},
  copyQuery: {},
  searchList: [
    {
      componentType: 'input',
      label: '项目名称',
      value: 'nameLike',
      event: search,
    },
    {
      value: 'projectTypeMult',
      componentType: 'select-model',
      code: 'project_type',
      multiple: true,
      label: '项目类别',
      event: search,
    },
  ],
  searchBtn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '重置', event: clearSearch },
  ],
  btnList: [
    {
      type: 'button',
      label: '新增',
      event: create,
      show: proxy.$permission('biddingParameter:add'),
    },
  ],
})
const clearType = ref(true)
// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  data: [],
  api: undefined,
  selections: [],
  fieldList: [
    {
      label: '项目名称',
      value: 'name',
      type: 'slot',
    },
    { label: '项目类别', value: 'projectTypeValue' },
    { label: '备注', value: 'remark' },
    { label: '创建人', value: 'createUserName' },
    { label: '创建时间', value: 'createTime' },
    { label: '更新人', value: 'updateUserName' },
    { label: '更新时间', value: 'updateTime' },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '修改',
        event: update,
        show: proxy.$permission('biddingParameter:update'),
      },
      {
        label: '删除',
        event: remove,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: proxy.$permission('biddingParameter:delete'),
      },
    ],
  },
})
const modifyInfo = ref({
  visible: false,
  orderId: '',
  title: '',
})

const detailInfo = ref({
  visible: false,
  orderId: '',
})

function returnModify() {
  if (modifyInfo.value.orderId) {
    getList()
  } else {
    search()
  }
}
onMounted(() => {
  filterInfo.value.copyQuery = filterInfo.value.query
})
//创建
function create() {
  modifyInfo.value.orderId = ''
  modifyInfo.value.title = '新增项目需求'
  modifyInfo.value.visible = true
}
function update(row) {
  sessionStorage.setItem('storeRowId', row.id)
  modifyInfo.value.orderId = row.id
  modifyInfo.value.title = '修改项目需求'
  modifyInfo.value.visible = true
}

//展示明细
function showDetail(row) {
  sessionStorage.setItem('storeRowId', row.id)
  detailInfo.value.orderId = row.id
  detailInfo.value.visible = true
}
function tableRowClassName({ row }) {
  let rowId = sessionStorage.getItem('storeRowId')
  if (rowId && row.id === Number(rowId)) {
    return 'check-row'
  }
  return ''
}
function remove(row) {
  delParameter([row.id]).then((res) => {
    if (res && res.success) {
      getList()
    }
  })
}
function clearSearch() {
  clearType.value = !clearType.value
  filterInfo.value.query = proxy.$fn.deepClone(filterInfo.value.copyQuery)
  search()
}
function getList() {
  tableInfo.value.api = getParameterPage
  tableInfo.value.refresh = Math.random()
}
function search() {
  tableInfo.value.api = getParameterPage
  tableInfo.value.initCurpage = Math.random()
  tableInfo.value.refresh = Math.random()
}
getList()
</script>

<style scoped></style>
